"======================================================================
"
" init-plugin-ui.vim - UI样式插件
"
"======================================================================

"----------------------------------------------------------------------
" 插件 --- startify 
"----------------------------------------------------------------------
let g:startify_custom_header          = [
\'',
\'',
\' TTTTTTTTTTTTTTTTTTTTTTT                              VVVVVVVV           VVVVVVVV iiii                             ',
\' T:::::::::::::::::::::T                              V::::::V           V::::::Vi::::i                            ',
\' T:::::::::::::::::::::T                              V::::::V           V::::::V iiii                             ',
\' T:::::TT:::::::TT:::::T                              V::::::V           V::::::V                                  ',
\' TTTTTT  T:::::T  TTTTTTooooooooooo   ppppp   pppppppppV:::::V           V:::::Viiiiiii    mmmmmmm    mmmmmmm      ',
\'         T:::::T      oo:::::::::::oo p::::ppp:::::::::pV:::::V         V:::::V i:::::i  mm:::::::m  m:::::::mm    ',
\'         T:::::T     o:::::::::::::::op:::::::::::::::::pV:::::V       V:::::V   i::::i m::::::::::mm::::::::::m   ',
\'         T:::::T     o:::::ooooo:::::opp::::::ppppp::::::pV:::::V     V:::::V    i::::i m::::::::::::::::::::::m   ',
\'         T:::::T     o::::o     o::::o p:::::p     p:::::p V:::::V   V:::::V     i::::i m:::::mmm::::::mmm:::::m   ',
\'         T:::::T     o::::o     o::::o p:::::p     p:::::p  V:::::V V:::::V      i::::i m::::m   m::::m   m::::m   ',
\'         T:::::T     o::::o     o::::o p:::::p     p:::::p   V:::::V:::::V       i::::i m::::m   m::::m   m::::m   ',
\'         T:::::T     o::::o     o::::o p:::::p    p::::::p    V:::::::::V        i::::i m::::m   m::::m   m::::m   ',
\'       TT:::::::TT   o:::::ooooo:::::o p:::::ppppp:::::::p     V:::::::V        i::::::im::::m   m::::m   m::::m   ',
\'       T:::::::::T   o:::::::::::::::o p::::::::::::::::p       V:::::V         i::::::im::::m   m::::m   m::::m   ',
\'       T:::::::::T    oo:::::::::::oo  p::::::::::::::pp         V:::V          i::::::im::::m   m::::m   m::::m   ',
\'       TTTTTTTTTTT      ooooooooooo    p::::::pppppppp            VVV           iiiiiiiimmmmmm   mmmmmm   mmmmmm   ',
\'                                       p:::::p                                                                     ',
\'                                       p:::::p                                                                     ',
\'                                      p:::::::p                                                                    ',
\'                                      p:::::::p                                                                    ',
\'                                      p:::::::p                                                                    ',
\'                                      ppppppppp                                                                    ',
\]
let g:startify_session_persistence    = 1
let g:startify_session_delete_buffers = 1
let g:startify_change_to_dir          = 0
let g:startify_change_to_vcs_root     = 1
let g:startify_fortune_use_unicode    = 1
let g:startify_padding_left           = 3
let g:startify_enable_special         = 0
let g:startify_session_number         = 10
nmap <silent>,w  :Startify<cr>
nmap <Leader>pp :SLoad<cr>
nmap <Leader>ps :SSave<cr>
nmap <Leader>pd :SDelete<cr>
nmap <Leader>pc :SClose<cr>


"----------------------------------------------------------------------
" 插件 --- indentline 
"----------------------------------------------------------------------
let g:indentLine_bufNameExclude      = [
    \    'defx'
    \ ]
let g:indentLine_leadingSpaceEnabled = 1
let g:indentLine_setColors = 1
let g:indentLine_leadingSpaceChar = '·'



"----------------------------------------------------------------------
" 插件 --- lightline 
"----------------------------------------------------------------------
let g:lightline#bufferline#show_number       = 2
let g:lightline#bufferline#number_map        = { 0: ' ', 1: '⓵ ', 2: '⓶ ', 3: '⓷ ', 4: '⓸ ', 5: '⓹ ', 6: '⓺ ', 7: '⓻ ', 8: '⓼ ', 9: '⓽ ' }
let g:lightline#bufferline#shorten_path      = 0
let g:lightline#bufferline#unnamed           = '[No Name]'
let g:lightline#bufferline#filename_modifier = ':t'
let g:lightline#bufferline#enable_devicons   = 1
let g:lightline#bufferline#unicode_symbols   = 1
let g:lightline                              = {
    \ 'colorscheme':'onedark',
    \ 'active': {
    \   'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'gutter' ], [ 'cocstatus' ] ],
    \   'right': [ [ 'tabs' ], [ 'syntastic', 'lineinfo' ], [ 'percent' ], [ 'filetype', 'fileformat', 'fileencoding' ] ]
    \ },
    \ 'tabline': { 'left': [ [ 'buffers' ] ], 'right': [ [ 'close' ] ] },
    \ 'tab': {
    \   'active': [ 'tabnum' ],
    \   'inactive': [ 'tabnum' ]
    \ },
    \ 'component': { 'lineinfo': ' %3l:%-2v' },
    \ 'component_expand': { 'buffers': 'lightline#bufferline#buffers' },
    \ 'component_type': { 'buffers': 'tabsel' },
    \ 'component_function': {
    \   'readonly': 'LightlineReadonly',
    \   'fugitive': 'LightlineFugitive',
    \   'gutter': 'LightlineGutter',
    \   'cocstatus': 'coc#status'
    \ },
    \ 'separator': { 'left': '', 'right': '' },
    \ 'subseparator': { 'left': '', 'right': '' }
    \ }
" 只读文件显示
function! LightlineReadonly()
    return &readonly ? '' : ''
endfunction
" Fugitvie
function! LightlineFugitive()
    if exists('*FugitiveHead')
        let branch = FugitiveHead()
        return branch !=# '' ? ''.branch : ''
    endif
    return ''
endfunction
" Gutter
function! LightlineGutter()
  let [a,m,r] = GitGutterGetHunkSummary()
  return printf(' %d  %d  %d', a, m, r)
endfunction

nmap <Leader>1 <plug>lightline#bufferline#go(1)
nmap <Leader>2 <plug>lightline#bufferline#go(2)
nmap <Leader>3 <plug>lightline#bufferline#go(3)
nmap <Leader>4 <plug>lightline#bufferline#go(4)
nmap <Leader>5 <plug>lightline#bufferline#go(5)
nmap <Leader>6 <plug>lightline#bufferline#go(6)
nmap <Leader>7 <plug>lightline#bufferline#go(7)
nmap <Leader>8 <plug>lightline#bufferline#go(8)
nmap <Leader>9 <plug>lightline#bufferline#go(9)
nmap <Leader>0 <plug>lightline#bufferline#go(10)


"----------------------------------------------------------------------
" 插件 --- defx 
"----------------------------------------------------------------------
call defx#custom#option('_', {
    \ 'columns': 'git:mark:indent:icon:icons:filename',
    \ 'winwidth': 25,
    \ 'split': 'vertical',
    \ 'direction': 'topleft',
    \ 'show_ignored_files': 0,
    \ 'toggle': 1,
    \ 'buffer_name': 'defx',
    \ 'root_marker': '$',
    \ 'ignored_files': '*.pyc'
    \ })
call defx#custom#column('icon', {
    \ 'directory_icon': '▸',
    \ 'opened_icon': '▾',
    \ 'root_icon': '➤',
    \ })
call defx#custom#column('filename', {
    \ 'root_marker_highlight': 'Ignore',
    \ 'min_width': 25,
    \ 'max_width': 50,
    \ })

call defx#custom#column('mark', {
    \ 'readonly_icon': '✗',
    \ 'selected_icon': '✓',
    \ })

" 打开文件树
nmap <silent>,e :Defx<cr>
" 在文件树中显示当前文件
nmap <Leader>lf :Defx `expand('%:p:h')` -search=`expand('%:p')`<cr>
" 自动更新文件树状态
autocmd BufWritePost * call defx#redraw()
" 文件树操作
autocmd FileType defx call s:defx_my_settings()
function! s:defx_my_settings() abort
    " 查看
    nmap <silent><buffer><expr> h       defx#do_action('cd', ['..'])
    nmap <silent><buffer><expr> l       defx#is_directory() ? defx#do_action('open_directory') : defx#do_action('print')
    nmap <silent><buffer><expr> o       defx#do_action('open_or_close_tree')
    " 打开
    nmap <silent><buffer><expr> <cr>    defx#do_action('drop')
    nmap <silent><buffer><expr> V       defx#do_action('open', 'vsplit')
    nmap <silent><buffer><expr> H       defx#do_action('open', 'horizontal')
    " 修改
    nmap <silent><buffer><expr> c       defx#do_action('copy')
    nmap <silent><buffer><expr> x       defx#do_action('move')
    nmap <silent><buffer><expr> p       defx#do_action('paste')
    nmap <silent><buffer><expr> D       defx#do_action('remove')
    nmap <silent><buffer><expr> r       defx#do_action('rename')
    " 新建
    nmap <silent><buffer><expr> d       defx#do_action('new_directory')
    nmap <silent><buffer><expr> f       defx#do_action('new_file')
    " 复制路径
    nmap <silent><buffer><expr> y       defx#do_action('yank_path')
    " 显示隐藏文件
    nmap <silent><buffer><expr> .       defx#do_action('toggle_ignored_files')
    " 退出
    nmap <silent><buffer><expr> q       defx#do_action('quit')
    " 选择
    nmap <silent><buffer><expr> <space> defx#do_action('toggle_select') . 'j'
    nmap <silent><buffer><expr> *       defx#do_action('toggle_select_all')
    " 增大窗口
	nmap <silent><buffer><expr> =       defx#do_action('resize', defx#get_context().winwidth + 1)
    " 缩小窗口
	nmap <silent><buffer><expr> -       defx#do_action('resize', defx#get_context().winwidth - 1)
endfunction


"----------------------------------------------------------------------
" 插件 --- TagbarToggle
" git变更显示
"----------------------------------------------------------------------
" TagBar显示
nmap <silent>,t :TagbarToggle<CR>


"----------------------------------------------------------------------
" 插件 --- gitgutter
" git变更显示
"----------------------------------------------------------------------
let g:gitgutter_sign_added              = ''
let g:gitgutter_sign_modified           = ''
let g:gitgutter_sign_removed            = ''
let g:gitgutter_sign_removed_first_line = ''
let g:gitgutter_sign_modified_removed   = ''
let g:gitgutter_grep                    = ''
" 禁止插件原始的快捷键
let g:gitgutter_map_keys                = 0
" 预览改动
nmap <Leader>dl <plug>(GitGutterPreviewHunk)
" 下一个改动
nmap <Leader>dn <plug>(GitGutterNextHunk)
" 上一个改动
nmap <Leader>dm <plug>(GitGutterPrevHunk)
